<?php

 /**
  * ---------------------------------------------------------------
  * CONNECTX CORE [API] SISCC 0.01
  * ---------------------------------------------------------------
  * @author Sergio Morlán Páramo
  */
 class Connectx {

     private $db_host, $db_user, $db_password, $db_database, $db_connection;



     /**
      * ---------------------------------------------------------------
      * CONSTRUCTOR
      * ---------------------------------------------------------------
      * @param string $p_host Dirección del servidor MySQL
      * @param string $p_user Usuario de la Base de Datos
      * @param string $p_password Contraseña correspondiente al usuario indicado
      * @param string $p_database Nombre de la Base de Datos
      */
     public function __construct($host="127.0.0.1", $user="root", $password="root", $database="SISCC") {
         /*
          * ---------------------------------------------------------------
          * CODIGO ORIGINAL
          * ---------------------------------------------------------------
           $this->db_host = $host;
           $this->db_user = $user;
           $this->db_password = $password;
           $this->db_database = $database;
          */

         /*
          * ---------------------------------------------------------------
          * ADAPTACIÓN PARA CODEIGNITER
          * ---------------------------------------------------------------
          */
         $this->ci = & get_instance();
         $this->ci->load->database();
         $this->db_host = $this->ci->db->hostname;
         $this->db_user = $this->ci->db->username;
         $this->db_password = $this->ci->db->password;
         $this->db_database = $this->ci->db->database;
         $this->setconnectionx();

     }




     /**
      * Conexión a la base de datos
      * @access private
      */
     private function setconnectionx() {
         $connect = mysql_connect($this->db_host, $this->db_user, $this->db_password);
         if ($connect) {
             mysql_select_db($this->db_database);
             $this->db_connection = $connect;
         }

     }




     /**
      * Obtener conexión
      * @return Resource  
      */
     protected function db_connection() {
         return $this->db_connection;

     }




     /**
      * Obtener Host
      * @return String 
      */
     protected function db_host() {
         return $this->db_host;

     }




     /**
      * Obtener Usuario
      * @return String 
      */
     protected function db_user() {
         return $this->db_user;

     }




     /**
      * Obtener Password
      * @return String
      */
     protected function db_password() {
         return $this->db_password;

     }




     /**
      * Obtener Nombre de Base de datos
      * @return String 
      */
     public function db_database() {
         return $this->database;

     }




     /**
      * Cerrar la conexión
      */
     public function close_connectx() {
         mysql_close($this->db_connection);

     }




 }

?>
